package com.example.activitytest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

//public class SecondActivity extends AppCompatActivity {
public class SecondActivity extends BaseActivity {

    public static void actionStart(Context context,String data1,String data2){
        Intent intent = new Intent(context,SecondActivity.class);
        intent.putExtra("param1",data1);
        intent.putExtra("param2",data2);
        context.startActivity(intent);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("SecondActivity","Task id is"+getTaskId());
        setContentView(R.layout.activity_second);
//        Intent intent = getIntent();    //getIntent()启动 SecondActivity 的 Intent
//        String data = intent.getStringExtra("extra_data");  // getStringExtra() 传递字符数据、getIntExtra() 传递整型数据、getBooleanExtra()传递布尔型数据
//        log.d("SecondActivity",data);

        // 使用 startActivityForResult()方法来启动 SecondActivity,请求码时唯一值
        Button button2 = (Button) findViewById(R.id.button_2);
//        button2.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent();
//                intent.putExtra("data_return","Hello FirstActivity");
//                setResult(RESULT_OK,intent);  //setResult()是向上活动返回数据的。第一个参数返回处理结果；第二参数把带有数据的Intent传递回去，调用finsh()来销毁当前活动
//                finish();
//            }
//        });

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SecondActivity.actionStart(FirstActivity.this,"data1","data2");
            }
        });

    }
}